/*
 * $Id: client.prg 2011-12-28 17:26 riztan $
 */

/*
 * Funciones para uso en Servidor NetIO de Tpuy.
 *
 * Copyright 2011 Riztan Gutierrez <riztan / at / gmail.com>
 */

#include "tdolphin.ch"
#include "common.ch"

// Programas de Control de Tablas
#include "tpy_tabcanal.prg"
#include "tpy_tables.prg"

function Analice( cFile )
   local cRes:="", aScript //,cProcesar
   local cLine, nPosI, nPosF, lIni:=.f.
   local cCode, oHrb
   local nBlock := 4096

   default cFile to "tpy_test01.xbs"

   if !File(cFile)
      return ""
   endif

//? cFile
//   nHand := FOpen(cFile) //, FO_READ)

   aScript := hb_aTokens( MemoRead(cFile), hb_eol() )

   if Len(aScript)<=0
      Return ""
   endif

//? LEN(aScript)

   for each cLine IN aScript

      //? cLine:__enumIndex, " ", cLine:__enumValue
      cLine := cLine:__enumValue

      nPosI := AT("<hb>",cLine)
      if nPosI > 0 .and. !lIni
         lIni := !lIni
         //cProcesar := ""

         nPosF := AT("</hb>",cLine)
         if nPosF > 0 .AND. nPosF > nPosI

            cCode := "function start() "+CRLF
            cCode += "return "
            cCode +=  STRTRAN(STRTRAN(SUBSTR(cLine,nPosI,nPosF),"<hb>"),"</hb>")+CRLF

            oHrb = HB_CompileFromBuf( cCode, "-n", "-p", "-q2", {"-I/usr/local/include/harbour"} )
            //? hb_HrbRun( oHrb )

            cLine :=  STUFF(cLine, nPosI, nPosF, hb_HrbRun( oHrb ) )

         endif
      endif

      cRes += cLine + hb_eol()
//? cRes

   next

return cRes



function tpy_test()
/*
   LOCAL cScript

   cScript := "#include 'gclass.ch' "+CRLF
   cScript += "proce script() "+CRLF
   cScript += "  Local oWnd "+CRLF
   cScript += "  DEFINE WINDOW oWnd TITLE 'Desde el Server!!' "+CRLF
   cScript += "  ACTIVATE WINDOW oWnd "+CRLF
   cScript += "return "+CRLF

//? cScript
*/
//return memoread('main.xbs')
return Analice()


function Script( cFile )
   local cNombre

   if UPPER(RIGHT(ALLTRIM(cFile),4))=".XBS"
      Return Analice(cFile)
   endif

return Analice(cFile+".xbs")


//eof
